
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Mr Bao
 */
public class UploadImage extends List implements CommandListener, Runnable {

    private UpAnh upAnh;
    private Command cmdBack = new Command("Back", Command.BACK, 2);
    private Command cmdNew = new Command("Them", Command.OK, 2);
    private int total;

    public UploadImage(UpAnh upAnh) {
        super("Dang anh", IMPLICIT);
        this.upAnh = upAnh;
        upAnh.client.ViewAlbum();
        addCommand(cmdBack);
        addCommand(cmdNew);
        setCommandListener(this);
        append("Them moi Album", null);
        total = 1;
        new Thread(this).start();
    }

    public void commandAction(Command c, Displayable d) {
        if (c == cmdBack) {
            upAnh.DisplayHomeMain();
        } else if (c == cmdNew) {
            upAnh.DisplayAddAlbum();
        } else if (c == SELECT_COMMAND) {
            if (getSelectedIndex() == total - 1) {
                upAnh.DisplayAddAlbum();
            } else {
                upAnh.albumIndex = getSelectedIndex();
                upAnh.DisplayUpAnhChose();
            }
        }
    }

    public void run() {
        while (true) {
            if (upAnh.client.listAlbum.size() > 0) {
                this.deleteAll();
                for (int i = 0; i < upAnh.client.listAlbum.size() - 1; i++) {
                    append(upAnh.client.listAlbum.elementAt(i).toString(), null);
                }
                total = upAnh.client.listAlbum.size();
                append("Them moi Album", null);
                upAnh.client.listAlbum = null;
                return;
            }
            System.gc();
        }
    }
}
